package org.example.managere.repository.feibiao;

import org.example.managere.entity.feibiao.AmAapOutput;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * 工况特定输出参数表 Repository
 */
public interface AmAapOutputRepository extends JpaRepository<AmAapOutput, Integer>, JpaSpecificationExecutor<AmAapOutput> {
    
    /**
     * 根据电机ID查询
     */
    List<AmAapOutput> findByMotorId(String motorId);
    
    /**
     * 根据电机状态查询
     */
    Page<AmAapOutput> findByMotorState(AmAapOutput.MotorState motorState, Pageable pageable);
    
    /**
     * 根据关键词搜索（电机ID或维护建议）
     */
    @Query("SELECT a FROM AmAapOutput a WHERE a.motorId LIKE %:keyword% OR a.maintenanceRecommendation LIKE %:keyword%")
    Page<AmAapOutput> search(@Param("keyword") String keyword, Pageable pageable);
    
    /**
     * 查询剩余使用寿命低于指定阈值的记录
     */
    Page<AmAapOutput> findByRemainingUsefulLifeLessThan(Float threshold, Pageable pageable);
    
    /**
     * 查询异常指数高于指定阈值的记录
     */
    @Query("SELECT a FROM AmAapOutput a WHERE a.anomalyScore > :threshold ORDER BY a.anomalyScore DESC")
    Page<AmAapOutput> findHighRiskMotors(@Param("threshold") java.math.BigDecimal threshold, Pageable pageable);
} 